home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / demobook / colorview.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  57.4 KB  |  2,017 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. /*******************************************************************************
  19.     colorview.c
  20. *******************************************************************************/
  21.  
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <ctype.h>
  26. #include <Xm/Xm.h>
  27. #include <Xm/MenuShell.h>
  28. #include "UxXt.h"
  29.  
  30. #include <Xm/List.h>
  31. #include <Xm/ScrolledW.h>
  32. #include <Xm/PushB.h>
  33. #include <Xm/LabelG.h>
  34. #include <Xm/Text.h>
  35. #include <Xm/TextF.h>
  36. #include <Xm/DrawingA.h>
  37. #include <Xm/DrawnB.h>
  38. #include <Xm/Frame.h>
  39. #include <Xm/CascadeB.h>
  40. #include <Xm/SeparatoG.h>
  41. #include <Xm/PushBG.h>
  42. #include <Xm/RowColumn.h>
  43. #include <Xm/Form.h>
  44. #include <X11/Shell.h>
  45.  
  46. /*******************************************************************************
  47.     Includes, Defines, and Global variables from the Declarations Editor:
  48. *******************************************************************************/
  49.  
  50. /*------------------------------------------------
  51.  * Visual Edge Software Limited.   December 1990.
  52.  *
  53.  * Color view
  54.  *-----------------------------------------------*/
  55. #include <X11/Xutil.h>
  56. #include <X11/Xos.h>
  57. #include <Xm/Protocols.h>
  58. #include <Xm/AtomMgr.h>
  59. #include <X11/cursorfont.h>
  60.  
  61. #include "exinterfmotif.h"
  62. #include <string.h>
  63. #include "exglobals.h"
  64. #include "exbookglo.h"
  65. #include "exinterf.h"
  66.  
  67. #define colorview_width 40
  68. #define colorview_height 45
  69. static char colorview_bits[] = {
  70.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff,
  71.    0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0xff, 0x0f, 0x70, 0x55, 0x55, 0x55,
  72.    0x0d, 0xb0, 0xaa, 0xaa, 0xaa, 0x0a, 0x70, 0x55, 0x55, 0x55, 0x0d, 0xb0,
  73.    0xaa, 0xaa, 0xaa, 0x0a, 0x70, 0x55, 0x55, 0x55, 0x0d, 0xb0, 0xaa, 0xaa,
  74.    0xaa, 0x0a, 0x70, 0x55, 0x55, 0x55, 0x0d, 0xb0, 0xaa, 0xaa, 0xaa, 0x0a,
  75.    0x70, 0x55, 0x55, 0x55, 0x0d, 0xb0, 0xaa, 0xaa, 0xaa, 0x0a, 0x70, 0x55,
  76.    0x55, 0x55, 0x0d, 0xb0, 0xaa, 0xaa, 0xaa, 0x0a, 0xf0, 0xff, 0xff, 0xff,
  77.    0x0f, 0x00, 0x2a, 0x00, 0x54, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x0f, 0x10,
  78.    0x00, 0x00, 0x00, 0x08, 0xd0, 0xfb, 0xbe, 0xef, 0x0b, 0xc8, 0xfb, 0xbe,
  79.    0xef, 0x13, 0x68, 0x9a, 0xa6, 0x69, 0x14, 0xe8, 0xfb, 0xbe, 0xef, 0x17,
  80.    0x08, 0x00, 0x00, 0x00, 0x10, 0xe8, 0xfb, 0xbe, 0xef, 0x17, 0xe8, 0xfb,
  81.    0xbe, 0xef, 0x17, 0x24, 0x9a, 0xa6, 0x69, 0x24, 0x34, 0x9a, 0xa6, 0x69,
  82.    0x2c, 0x34, 0x9a, 0xa6, 0x69, 0x28, 0xf4, 0xfb, 0xbe, 0xef, 0x2f, 0x04,
  83.    0x00, 0x00, 0x00, 0x20, 0xfc, 0xff, 0xff, 0xff, 0x3f, 0x54, 0x55, 0x55,
  84.    0x55, 0x35, 0xac, 0xaa, 0xaa, 0xaa, 0x2a, 0xf8, 0xff, 0xff, 0xff, 0x1f,
  85.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  86.    0x00, 0x80, 0x03, 0xf8, 0xff, 0xff, 0xff, 0x0d, 0x04, 0x00, 0x00, 0xf4,
  87.    0x7f, 0xf8, 0xff, 0xff, 0xff, 0x0e, 0x00, 0x00, 0x00, 0x80, 0x43, 0x00,
  88.    0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00};
  89.  
  90. #define RGB_FILE "/usr/lib/X11/rgb.txt" 
  91. #define MAX_DB_COLORS 1000 
  92. #define MAX_BUFSIZE   50 
  93. #define MAX_COLORS    256 
  94. /* Numbers of color cells  
  95.  */ 
  96. #define N_PALETTE 12
  97. #define N_CUES 11
  98. Colormap sys_cmap;
  99.  
  100. float current_AGColors[12][3];
  101. float initial_AGColors[12][3] = {
  102.         {1.0,0.0,0.0},       /* 1 Red */
  103.         {0.0,0.0,1.0},       /* 2 Blue */
  104.         {0.627,0.125,0.941}, /* 3 Purple */
  105.         {0.275,0.510,0.706}, /* 4 SteelBlue */
  106.         {0.133,0.545,0.133}, /* 5 ForestGreen */
  107.         {0.439,0.500,0.565}, /* 6 SlateGrey */
  108.         {0.690,0.188,0.376}, /* 7 maroon */
  109.         {0.392,0.584,0.930}, /* 8 CornflowerBlue */
  110.         {0.870,0.722,0.530}, /* 9 burlywood */
  111.         {0.914,0.588,0.478}, /* 10 DarkSalmon */
  112.         {0.000,0.808,0.820}, /* 11 DarkTurquoise */
  113.         {1.000,0.937,0.835}, /* 12 PapayaWhip */
  114. };
  115.  
  116. /* Read/Write color cells for editing.
  117.  */
  118. XColor  palette_colors [N_PALETTE];     /* view palette         */
  119. XColor  editor_color;            /* active color in the editor     */
  120. XColor  cue_colors [N_CUES];        /* color editor cues        */
  121. /* Initial state of the palette (before editing).
  122.  */
  123. XColor  initial_palette_colors [N_PALETTE];
  124. /* Entries from the color database.
  125.  */
  126. char db_color_names [MAX_DB_COLORS] [MAX_BUFSIZE];
  127. int  num_color_names = 0;
  128. /* Child interfaces.
  129.  */
  130. extern Widget coloredit;
  131. extern Widget create_coloredit ();
  132. extern char *regcmp ();
  133. extern char *regex ();
  134. extern void new_init_color ();
  135. extern void copy_color ();
  136. extern char* color_string ();
  137. static void X_to_GL_color ();
  138. static void setup_colors ();
  139. static void read_color_db ();
  140. static void setup_palette ();
  141. static void activate_color ();
  142. static void open_color_editor ();
  143. static void filter_color_names ();
  144. static void WmCloseCallback ();
  145. char* GL_to_X_color_string ();
  146.  
  147. static long CVwin;
  148.  
  149. /*******************************************************************************
  150.     The definition of the context structure:
  151.     If you create multiple instances of your interface, the context
  152.     structure ensures that your callbacks use the variables for the
  153.     correct instance.
  154.  
  155.     For each swidget in the interface, each argument to the Interface
  156.     function, and each variable in the Instance Specific section of the
  157.     Declarations Editor, there is an entry in the context structure.
  158.     and a #define.  The #define makes the variable name refer to the
  159.     corresponding entry in the context structure.
  160. *******************************************************************************/
  161.  
  162. typedef    struct
  163. {
  164.     Widget    Uxbody_fm;
  165.     Widget    Uxmain_pd;
  166.     Widget    Uxmain_pd_p2;
  167.     Widget    Uxmain_pd_p2_b1;
  168.     Widget    Uxmain_pd_p2_b2;
  169.     Widget    Uxmain_pd_p2_b3;
  170.     Widget    Uxmain_pd_top_b2;
  171.     Widget    Uxcolors_box;
  172.     Widget    Uxcolors_fm;
  173.     Widget    Uxcolor_1;
  174.     Widget    Uxcolor_5;
  175.     Widget    Uxcolor_7;
  176.     Widget    Uxcolor_9;
  177.     Widget    Uxcolor_11;
  178.     Widget    Uxcolor_2;
  179.     Widget    Uxcolor_6;
  180.     Widget    Uxcolor_8;
  181.     Widget    Uxcolor_10;
  182.     Widget    Uxcolor_12;
  183.     Widget    Uxcolor_3;
  184.     Widget    Uxcolor_4;
  185.     Widget    Uxcolor_txt;
  186.     Widget    Uxbrowser_box;
  187.     Widget    Uxbrowser_fm;
  188.     Widget    Uxfilter_lbl;
  189.     Widget    Uxfilter_text;
  190.     Widget    Uxbrowser_lbl;
  191.     Widget    Uxfilter_btn;
  192.     Widget    Uxbrowser_sw;
  193.     Widget    Uxbrowser_sl;
  194.     Widget    Uxok_btn;
  195.     Widget    Uxcancel_btn;
  196.     Widget    Uxswatch_dsp;
  197.     Widget    Uxswatch_fm;
  198.     Widget    Uxpalette[N_PALETTE];
  199.     int    Uxactive_color;
  200. } _UxCcolorview;
  201.  
  202. #define body_fm                 UxColorviewContext->Uxbody_fm
  203. #define main_pd                 UxColorviewContext->Uxmain_pd
  204. #define main_pd_p2              UxColorviewContext->Uxmain_pd_p2
  205. #define main_pd_p2_b1           UxColorviewContext->Uxmain_pd_p2_b1
  206. #define main_pd_p2_b2           UxColorviewContext->Uxmain_pd_p2_b2
  207. #define main_pd_p2_b3           UxColorviewContext->Uxmain_pd_p2_b3
  208. #define main_pd_top_b2          UxColorviewContext->Uxmain_pd_top_b2
  209. #define colors_box              UxColorviewContext->Uxcolors_box
  210. #define colors_fm               UxColorviewContext->Uxcolors_fm
  211. #define color_1                 UxColorviewContext->Uxcolor_1
  212. #define color_5                 UxColorviewContext->Uxcolor_5
  213. #define color_7                 UxColorviewContext->Uxcolor_7
  214. #define color_9                 UxColorviewContext->Uxcolor_9
  215. #define color_11                UxColorviewContext->Uxcolor_11
  216. #define color_2                 UxColorviewContext->Uxcolor_2
  217. #define color_6                 UxColorviewContext->Uxcolor_6
  218. #define color_8                 UxColorviewContext->Uxcolor_8
  219. #define color_10                UxColorviewContext->Uxcolor_10
  220. #define color_12                UxColorviewContext->Uxcolor_12
  221. #define color_3                 UxColorviewContext->Uxcolor_3
  222. #define color_4                 UxColorviewContext->Uxcolor_4
  223. #define color_txt               UxColorviewContext->Uxcolor_txt
  224. #define browser_box             UxColorviewContext->Uxbrowser_box
  225. #define browser_fm              UxColorviewContext->Uxbrowser_fm
  226. #define filter_lbl              UxColorviewContext->Uxfilter_lbl
  227. #define filter_text             UxColorviewContext->Uxfilter_text
  228. #define browser_lbl             UxColorviewContext->Uxbrowser_lbl
  229. #define filter_btn              UxColorviewContext->Uxfilter_btn
  230. #define browser_sw              UxColorviewContext->Uxbrowser_sw
  231. #define browser_sl              UxColorviewContext->Uxbrowser_sl
  232. #define ok_btn                  UxColorviewContext->Uxok_btn
  233. #define cancel_btn              UxColorviewContext->Uxcancel_btn
  234. #define swatch_dsp              UxColorviewContext->Uxswatch_dsp
  235. #define swatch_fm               UxColorviewContext->Uxswatch_fm
  236. #define palette                 UxColorviewContext->Uxpalette
  237. #define active_color            UxColorviewContext->Uxactive_color
  238.  
  239. static _UxCcolorview    *UxColorviewContext;
  240.  
  241. Widget    colorview;
  242.  
  243. /*******************************************************************************
  244.     The following are translation tables.
  245. *******************************************************************************/
  246.  
  247. static char    *view_trans = "#override\n\
  248. <Key>Return:ArmAndActivate()\n";
  249.  
  250. /*******************************************************************************
  251.     Forward declarations of functions that are defined later in this file.
  252. *******************************************************************************/
  253.  
  254. Widget  create_colorview();
  255. void    popup_colorview();
  256. void    popdown_colorview();
  257.  
  258. void setup_colors_widget()
  259. {
  260.    int numberofcolors;
  261.    struct grptmpltstruct *tmpgrp;
  262.    int j,i, k, n;
  263.    Boolean color_found;
  264.    Widget sw;
  265.  
  266.    numberofcolors = 0;
  267.    tmpgrp = firstgroup;
  268.    while (tmpgrp != NULL && numberofcolors < 12)
  269.       {
  270.       for (j = 0; j < 3; j++)
  271.          current_AGColors[numberofcolors][j] = tmpgrp->covercolor[j];
  272.       numberofcolors++;
  273.       tmpgrp = tmpgrp->nextgrp;
  274.       }
  275.      /* Setup rest of palette for color viewer and create color viewer */
  276.    if (numberofcolors < 12)
  277.       {
  278.       for (i = numberofcolors, n = 0; i <= 12; i++,n++)
  279.          {
  280.          color_found = FALSE;
  281.          for (k = 0; k < numberofcolors; k++)
  282.             {
  283.             if (match_color(current_AGColors[k], initial_AGColors[n]))
  284.                color_found = TRUE;
  285.             }
  286.          if (!color_found)
  287.             {
  288.             for (j = 0; j < 3; j++)
  289.                current_AGColors[i-1][j] = initial_AGColors[n][j];
  290.             }
  291.          }
  292.       }
  293.    sw = create_colorview();
  294. }
  295. /*******************************************************************************
  296.     Auxiliary code from the Declarations Editor:
  297. *******************************************************************************/
  298.  
  299. /* update_view () - external indication (sent by coloredit)
  300.  *             that the active color has been changed.
  301.  *            Coloredit has already written the new color to
  302.  *            the colorcell; all we need do is update the name.
  303.  */
  304.  
  305. void update_view () 
  306. {
  307.     XColor *color;
  308.     double r, g, b;
  309.     char* color_string_buf;
  310.     color_string_buf = (char *)malloc(32);
  311. /*
  312.     XtVaSetValues( color_txt, XmNvalue, 
  313.         color_string (&palette_colors[active_color]), NULL );
  314.     XtVaSetValues( color_txt, XmNcursorPosition,
  315.         strlen(color_string (&palette_colors[active_color])), NULL );
  316. */
  317.     color = &palette_colors[active_color];
  318.     r = (double) color->red   / 65535;
  319.     g = (double) color->green / 65535;
  320.     b = (double) color->blue  / 65535;
  321.     sprintf (color_string_buf, "%.2f %.2f %.2f", r, g, b);
  322. /*    printf (" %s\n", color_string_buf); */
  323.     XtVaSetValues( color_txt, XmNvalue, color_string_buf, NULL );
  324.     XtVaSetValues( color_txt, XmNcursorPosition, 14, NULL );
  325. }
  326.  
  327. /* Close callback - registered for mwm 'close' button.
  328.  */
  329.  
  330. static void WmCloseCallback (w, client_data, call_data)
  331.      Widget w;
  332.     caddr_t client_data;
  333.     XmAnyCallbackStruct *call_data;
  334. {
  335.     popdown_colorview();
  336. }
  337.  
  338. /* activate_color () - make the given palette entry the current color.
  339.  */
  340.  
  341. static void activate_color (n) 
  342.     int n;
  343. {
  344.     Arg args[2];
  345.  
  346.     XtVaSetValues( palette[active_color],
  347.         XmNshadowType, XmSHADOW_ETCHED_IN, NULL );
  348.     XtVaSetValues( palette[n],
  349.         XmNshadowType, XmSHADOW_IN, NULL );
  350.     active_color = n;
  351.     new_init_color (&palette_colors[n]);
  352. /*
  353.     XtVaSetValues( color_txt, XmNvalue, 
  354.         color_string (&palette_colors[n]), NULL );
  355.     XtVaSetValues( color_txt, XmNcursorPosition,
  356.         strlen(color_string (&palette_colors[n])), NULL );
  357. */
  358.     update_view();
  359.     XtVaSetValues( swatch_dsp,
  360.         XmNbackground, palette_colors[active_color].pixel, NULL );
  361. }
  362.  
  363. /* open_color () - pop up the color editor on the current active color.
  364.  */
  365.  
  366. static void open_color_editor (n) 
  367.     int n;
  368. {
  369.     if (n < 0 || n >= N_PALETTE) 
  370.         return;
  371.  
  372.     UxPopupInterface (coloredit, no_grab);
  373. }
  374.  
  375.  
  376. /* setup_colors() - allocate and initialize color cells for the editor.
  377.  */
  378.  
  379. static void setup_colors ()
  380. {
  381.       Arg arglist[10];
  382.       int i;
  383.       int pixels[N_PALETTE + N_CUES + 1];
  384.     
  385.       sys_cmap = DefaultColormap (UxDisplay,UxScreen);
  386.  
  387.       if (! XAllocColorCells (UxDisplay, sys_cmap, False, NULL, 0, 
  388.                      pixels,  
  389.                      N_PALETTE + N_CUES + 1)) {
  390.     fprintf (stderr, "Not enough color cells available for color editor.\n");
  391.     sprintf(msgstring, "Not enough color cells \navailable for color editor.");
  392.     DialogType = 1;
  393.     popup_Message();
  394.     popdown_colorview();
  395.       }
  396.  
  397.       /* Save the initial state of the palette,
  398.        * i.e. the background colors of the palette widgets.
  399.        */
  400.       for (i= 0; i < N_PALETTE; i++) {
  401.           XtSetArg (arglist[0], XmNbackground, &initial_palette_colors[i].pixel);
  402.           XtGetValues (palette[i], arglist,1);
  403.       initial_palette_colors[i].flags = DoRed | DoGreen | DoBlue;
  404.       }
  405.       XQueryColors (UxDisplay, sys_cmap, initial_palette_colors, N_PALETTE);
  406.  
  407.       /* Copy the initial palette into writeable palette color cells.
  408.        */
  409.       for (i = 0; i < N_PALETTE; i++) {
  410.           palette_colors[i].pixel= pixels[i];
  411.           palette_colors[i].flags= DoRed | DoGreen | DoBlue;
  412.           copy_color (&palette_colors[i], &initial_palette_colors[i]);
  413.       }
  414.       XStoreColors (UxDisplay, sys_cmap, palette_colors, N_PALETTE);
  415.  
  416.       /* Bind the writeable palette colors to the palette widgets.
  417.        */
  418.       for (i= 0; i < N_PALETTE; i++) {
  419.           XtSetArg (arglist[0], XmNbackground, palette_colors[i].pixel);
  420.           XtSetValues (palette[i], arglist,1);
  421.       }
  422.  
  423.       XtSetArg (arglist[0], XmNbackground, palette_colors[active_color].pixel);
  424.       XtSetValues (swatch_dsp, arglist, 1);
  425.  
  426.       /* Set up the writeable colors used in coloredit.
  427.        */
  428.       editor_color.pixel = pixels[N_PALETTE+N_CUES];
  429.       editor_color.flags = DoRed | DoGreen | DoBlue;
  430.       for (i=0; i < N_CUES; i++) {
  431.     cue_colors[i].pixel = pixels[N_PALETTE+i];
  432.     cue_colors[i].flags = DoRed | DoBlue | DoGreen;
  433.       }
  434.  
  435. }
  436.  
  437. /* read_color_db () - read the color database file.
  438.  */
  439.  
  440. static void read_color_db ()
  441. {
  442.     Arg arglist[5];
  443.     FILE *fp;
  444.     int i=0, ret;
  445.     XmString *item_list;
  446.  
  447.     if ((fp = fopen (RGB_FILE, "r")) == NULL) {
  448. /*
  449.         printf ("Can't open rgb database file: %s\n", RGB_FILE);
  450. */
  451.         sprintf(msgstring, "Can't open rgb database file:\n%s", RGB_FILE);
  452.         DialogType = 1;
  453.         popup_Message();
  454.         return;
  455.     }
  456.  
  457.     for (i=0; i<MAX_DB_COLORS; i++) {
  458.         ret = fscanf (fp, "%*d%*d%*d ");
  459.         if (ret == EOF)
  460.             break;
  461.         if (ret < 0) {
  462. /*
  463.             printf ("Couldn't read rgb file.  Error %d.\n", ret);
  464. */
  465.             sprintf(msgstring, "Couldn't read rgb file.\nError %d.", ret);
  466.             DialogType = 1;
  467.             popup_Message();
  468.             break;
  469.         }
  470.         if (fgets (db_color_names[i], MAX_BUFSIZE, fp) == NULL) {
  471. /*
  472.             printf ("Couldn't read color name.\n");
  473. */
  474.         sprintf(msgstring, "\nCouldn't read color name.\n");
  475.         DialogType = 1;
  476.         popup_Message();
  477.         break;
  478.         }
  479.         db_color_names[i][strlen (db_color_names[i]) - 1] = '\0';
  480.     }
  481.  
  482.     num_color_names = i;
  483.     filter_color_names ();
  484.       
  485.     fclose (fp);
  486.  
  487. }
  488.  
  489. /* filter_color_names () - apply the filter to the color database names,
  490.  *                         loading the result into the browser list.
  491.  */
  492. static void filter_color_names () 
  493. {
  494.     char *value, *reg;
  495.     char regvalue[MAX_BUFSIZE + 2];
  496.     char *nval = regvalue;
  497.     char *oval;
  498.     int numsubkeys=0, i;
  499.     XmString *item_list;
  500.     char *matched;
  501.     Arg arglist[5];
  502.  
  503.     value = XmTextGetString (filter_text);
  504.  
  505.     /* Convert filter string to regular grammar */
  506.     oval = value;
  507.     *nval++ = '^';
  508.     while (*oval) {
  509.         switch (*oval)
  510.         {
  511.             case '.':
  512.                 *nval++ = '\\';
  513.                 *nval++ = '.';
  514.                 break;
  515.             case '?':
  516.                 *nval++ = '.';
  517.                 break;
  518.             case '*':
  519.                 *nval++ = '.';
  520.                 *nval++ = '*';
  521.                 break;
  522.             default:
  523.                 *nval++ = *oval;
  524.         }
  525.         oval++;
  526.     }
  527.     *nval = '\0';
  528.     reg = regcmp (regvalue, 0);
  529.     
  530.     /* Set up item_list to hold sublist of color names */ 
  531.     
  532.     item_list = (XmString*) XtMalloc (num_color_names * sizeof(XmString));
  533.     for (i=0; i<num_color_names; i++) {
  534.         matched = regex (reg, db_color_names[i]);
  535.         if (matched) {
  536.                 item_list[numsubkeys++] = XmStringCreateLtoR ( 
  537.                         db_color_names[i],  
  538.                         XmSTRING_DEFAULT_CHARSET);
  539.         }
  540.     }
  541.     XtSetArg (arglist[0], XmNitems, item_list);
  542.           XtSetArg (arglist[1], XmNitemCount, numsubkeys);
  543.           XtSetValues (browser_sl, arglist, 2);
  544.           
  545.           for (i=0; i<numsubkeys; i++) {
  546.         XmStringFree(item_list[i]);
  547.     }
  548.           XtFree (item_list);
  549. }
  550.  
  551. /* setup_palette () - load the palette array with the actual palette widgets.
  552.  *             Must add/delete lines here when changing N_PALETTE. 
  553.  */
  554. static void setup_palette () 
  555. {
  556.     palette[0] = color_1;
  557.     palette[1] = color_2;
  558.     palette[2] = color_3;
  559.     palette[3] = color_4;
  560.     palette[4] = color_5;
  561.     palette[5] = color_6;
  562.     palette[6] = color_7;
  563.     palette[7] = color_8;
  564.     palette[8] = color_9;
  565.     palette[9] = color_10;
  566.     palette[10] = color_11;
  567.     palette[11] = color_12;
  568. }
  569.  
  570. /*******************************************************************************
  571.     The following are callback functions.
  572. *******************************************************************************/
  573.  
  574. static void    destroyCB_colorview( UxWidget, UxClientData, UxCallbackArg )
  575.     Widget        UxWidget;
  576.     XtPointer    UxClientData, UxCallbackArg;
  577. {
  578.     _UxCcolorview           *UxSaveCtx, *UxContext;
  579.  
  580.     UxSaveCtx = UxColorviewContext;
  581.     UxColorviewContext = UxContext =
  582.             (_UxCcolorview *) UxGetContext( UxWidget );
  583.     {
  584.     popdown_colorview();
  585.     }
  586.     UxColorviewContext = UxSaveCtx;
  587. }
  588.  
  589. static void    activateCB_main_pd_p2_b2( UxWidget, UxClientData, UxCallbackArg )
  590.     Widget        UxWidget;
  591.     XtPointer    UxClientData, UxCallbackArg;
  592. {
  593.     _UxCcolorview           *UxSaveCtx, *UxContext;
  594.  
  595.     UxSaveCtx = UxColorviewContext;
  596.     UxColorviewContext = UxContext =
  597.             (_UxCcolorview *) UxGetContext( UxWidget );
  598.     {
  599.     int i,j;
  600.     for (i = 0; i < N_PALETTE; i++) {
  601.         copy_color (&palette_colors[i], &initial_palette_colors[i]);
  602.         X_to_GL_color (&palette_colors[i], current_AGColors[i]);
  603. /*
  604.         for (j=0; j<3; j++)
  605.           current_AGColors[i][j] = initial_AGColors[i][j];
  606.         printf("R = %f  G = %f  B = %f\n", 
  607.           current_AGColors[i][0], current_AGColors[i][1], current_AGColors[i][2]); 
  608. */
  609.     }
  610.     XStoreColors (UxDisplay, sys_cmap, palette_colors, N_PALETTE);
  611.     update_view();
  612.     }
  613.     UxColorviewContext = UxSaveCtx;
  614. }
  615.  
  616. static void    activateCB_main_pd_p2_b3( UxWidget, UxClientData, UxCallbackArg )
  617.     Widget        UxWidget;
  618.     XtPointer    UxClientData, UxCallbackArg;
  619. {
  620.     _UxCcolorview           *UxSaveCtx, *UxContext;
  621.  
  622.     UxSaveCtx = UxColorviewContext;
  623.     UxColorviewContext = UxContext =
  624.             (_UxCcolorview *) UxGetContext( UxWidget );
  625.     {
  626.     int i,j;
  627.     for (i = 0; i < N_PALETTE; i++) {
  628.         copy_color (&palette_colors[i], &initial_palette_colors[i]);
  629. /*
  630.         for (j=0; j<3; j++)
  631.           current_AGColors[i][j] = initial_AGColors[i][j];
  632.         printf("R = %f  G = %f  B = %f\n", 
  633.           current_AGColors[i][0], current_AGColors[i][1], current_AGColors[i][2]); 
  634. */
  635.     }
  636.     XStoreColors (UxDisplay, sys_cmap, palette_colors, N_PALETTE);
  637.     update_view();
  638.     }
  639.     UxColorviewContext = UxSaveCtx;
  640. }
  641.  
  642.  
  643. static void    activateCB_main_pd_p2_b1( UxWidget, UxClientData, UxCallbackArg )
  644.     Widget        UxWidget;
  645.     XtPointer    UxClientData, UxCallbackArg;
  646. {
  647.     _UxCcolorview           *UxSaveCtx, *UxContext;
  648.  
  649.     UxSaveCtx = UxColorviewContext;
  650.     UxColorviewContext = UxContext =
  651.             (_UxCcolorview *) UxGetContext( UxWidget );
  652.     {
  653.     open_color_editor (active_color);
  654.     }
  655.     UxColorviewContext = UxSaveCtx;
  656. }
  657.  
  658. static void    activateCB_color_1( UxWidget, UxClientData, UxCallbackArg )
  659.     Widget        UxWidget;
  660.     XtPointer    UxClientData, UxCallbackArg;
  661. {
  662.     _UxCcolorview           *UxSaveCtx, *UxContext;
  663.  
  664.     UxSaveCtx = UxColorviewContext;
  665.     UxColorviewContext = UxContext =
  666.             (_UxCcolorview *) UxGetContext( UxWidget );
  667.     {
  668.     activate_color (0);
  669.     }
  670.     UxColorviewContext = UxSaveCtx;
  671. }
  672.  
  673. static void    activateCB_color_5( UxWidget, UxClientData, UxCallbackArg )
  674.     Widget        UxWidget;
  675.     XtPointer    UxClientData, UxCallbackArg;
  676. {
  677.     _UxCcolorview           *UxSaveCtx, *UxContext;
  678.  
  679.     UxSaveCtx = UxColorviewContext;
  680.     UxColorviewContext = UxContext =
  681.             (_UxCcolorview *) UxGetContext( UxWidget );
  682.     {
  683.     activate_color (4);
  684.     }
  685.     UxColorviewContext = UxSaveCtx;
  686. }
  687.  
  688. static void    activateCB_color_7( UxWidget, UxClientData, UxCallbackArg )
  689.     Widget        UxWidget;
  690.     XtPointer    UxClientData, UxCallbackArg;
  691. {
  692.     _UxCcolorview           *UxSaveCtx, *UxContext;
  693.  
  694.     UxSaveCtx = UxColorviewContext;
  695.     UxColorviewContext = UxContext =
  696.             (_UxCcolorview *) UxGetContext( UxWidget );
  697.     {
  698.     activate_color (6);
  699.     }
  700.     UxColorviewContext = UxSaveCtx;
  701. }
  702.  
  703. static void    activateCB_color_9( UxWidget, UxClientData, UxCallbackArg )
  704.     Widget        UxWidget;
  705.     XtPointer    UxClientData, UxCallbackArg;
  706. {
  707.     _UxCcolorview           *UxSaveCtx, *UxContext;
  708.  
  709.     UxSaveCtx = UxColorviewContext;
  710.     UxColorviewContext = UxContext =
  711.             (_UxCcolorview *) UxGetContext( UxWidget );
  712.     {
  713.     activate_color (8);
  714.     }
  715.     UxColorviewContext = UxSaveCtx;
  716. }
  717.  
  718. static void    activateCB_color_11( UxWidget, UxClientData, UxCallbackArg )
  719.     Widget        UxWidget;
  720.     XtPointer    UxClientData, UxCallbackArg;
  721. {
  722.     _UxCcolorview           *UxSaveCtx, *UxContext;
  723.  
  724.     UxSaveCtx = UxColorviewContext;
  725.     UxColorviewContext = UxContext =
  726.             (_UxCcolorview *) UxGetContext( UxWidget );
  727.     {
  728.     activate_color (10);
  729.     }
  730.     UxColorviewContext = UxSaveCtx;
  731. }
  732.  
  733. static void    activateCB_color_2( UxWidget, UxClientData, UxCallbackArg )
  734.     Widget        UxWidget;
  735.     XtPointer    UxClientData, UxCallbackArg;
  736. {
  737.     _UxCcolorview           *UxSaveCtx, *UxContext;
  738.  
  739.     UxSaveCtx = UxColorviewContext;
  740.     UxColorviewContext = UxContext =
  741.             (_UxCcolorview *) UxGetContext( UxWidget );
  742.     {
  743.     activate_color (1);
  744.     }
  745.     UxColorviewContext = UxSaveCtx;
  746. }
  747.  
  748. static void    activateCB_color_6( UxWidget, UxClientData, UxCallbackArg )
  749.     Widget        UxWidget;
  750.     XtPointer    UxClientData, UxCallbackArg;
  751. {
  752.     _UxCcolorview           *UxSaveCtx, *UxContext;
  753.  
  754.     UxSaveCtx = UxColorviewContext;
  755.     UxColorviewContext = UxContext =
  756.             (_UxCcolorview *) UxGetContext( UxWidget );
  757.     {
  758.     activate_color (5);
  759.     }
  760.     UxColorviewContext = UxSaveCtx;
  761. }
  762.  
  763. static void    activateCB_color_8( UxWidget, UxClientData, UxCallbackArg )
  764.     Widget        UxWidget;
  765.     XtPointer    UxClientData, UxCallbackArg;
  766. {
  767.     _UxCcolorview           *UxSaveCtx, *UxContext;
  768.  
  769.     UxSaveCtx = UxColorviewContext;
  770.     UxColorviewContext = UxContext =
  771.             (_UxCcolorview *) UxGetContext( UxWidget );
  772.     {
  773.     activate_color (7);
  774.     }
  775.     UxColorviewContext = UxSaveCtx;
  776. }
  777.  
  778. static void    activateCB_color_10( UxWidget, UxClientData, UxCallbackArg )
  779.     Widget        UxWidget;
  780.     XtPointer    UxClientData, UxCallbackArg;
  781. {
  782.     _UxCcolorview           *UxSaveCtx, *UxContext;
  783.  
  784.     UxSaveCtx = UxColorviewContext;
  785.     UxColorviewContext = UxContext =
  786.             (_UxCcolorview *) UxGetContext( UxWidget );
  787.     {
  788.     activate_color (9);
  789.     }
  790.     UxColorviewContext = UxSaveCtx;
  791. }
  792.  
  793. static void    activateCB_color_12( UxWidget, UxClientData, UxCallbackArg )
  794.     Widget        UxWidget;
  795.     XtPointer    UxClientData, UxCallbackArg;
  796. {
  797.     _UxCcolorview           *UxSaveCtx, *UxContext;
  798.  
  799.     UxSaveCtx = UxColorviewContext;
  800.     UxColorviewContext = UxContext =
  801.             (_UxCcolorview *) UxGetContext( UxWidget );
  802.     {
  803.     activate_color (11);
  804.     }
  805.     UxColorviewContext = UxSaveCtx;
  806. }
  807.  
  808. static void    activateCB_color_3( UxWidget, UxClientData, UxCallbackArg )
  809.     Widget        UxWidget;
  810.     XtPointer    UxClientData, UxCallbackArg;
  811. {
  812.     _UxCcolorview           *UxSaveCtx, *UxContext;
  813.  
  814.     UxSaveCtx = UxColorviewContext;
  815.     UxColorviewContext = UxContext =
  816.             (_UxCcolorview *) UxGetContext( UxWidget );
  817.     {
  818.     activate_color (2);
  819.     }
  820.     UxColorviewContext = UxSaveCtx;
  821. }
  822.  
  823. static void    activateCB_color_4( UxWidget, UxClientData, UxCallbackArg )
  824.     Widget        UxWidget;
  825.     XtPointer    UxClientData, UxCallbackArg;
  826. {
  827.     _UxCcolorview           *UxSaveCtx, *UxContext;
  828.  
  829.     UxSaveCtx = UxColorviewContext;
  830.     UxColorviewContext = UxContext =
  831.             (_UxCcolorview *) UxGetContext( UxWidget );
  832.     {
  833.     activate_color (3);
  834.     }
  835.     UxColorviewContext = UxSaveCtx;
  836. }
  837.  
  838. static void    activateCB_color_txt( UxWidget, UxClientData, UxCallbackArg )
  839.     Widget        UxWidget;
  840.     XtPointer    UxClientData, UxCallbackArg;
  841. {
  842.     _UxCcolorview           *UxSaveCtx, *UxContext;
  843.  
  844.     UxSaveCtx = UxColorviewContext;
  845.     UxColorviewContext = UxContext =
  846.             (_UxCcolorview *) UxGetContext( UxWidget );
  847.     {
  848.     char *newname;
  849.     char *color_string;
  850.     Boolean GLParseColor();
  851.  
  852.     newname = (char *)XmTextFieldGetString (UxWidget);
  853.     color_string = (char *)malloc( sizeof(char) * 32);
  854.     color_string[0] = '\0';
  855.     if (!GLParseColor (newname, color_string)) {
  856.         sprintf(msgstring, "problem parsing GL color %s\n", newname);
  857.         DialogType = 1;
  858.         popup_Message();
  859.         return;
  860.     }
  861.     if (!XParseColor (UxDisplay, sys_cmap, color_string, &palette_colors[active_color])) {
  862.         sprintf(msgstring, "problem parsing color %s\n", color_string);
  863.         DialogType = 1;
  864.         popup_Message();
  865.         return;
  866.     }
  867.     XStoreColor (UxDisplay,sys_cmap,&palette_colors[active_color]);
  868.     }
  869.     UxColorviewContext = UxSaveCtx;
  870. }
  871.  
  872. static void    losingFocusCB_filter_text( UxWidget, UxClientData, UxCallbackArg )
  873.     Widget        UxWidget;
  874.     XtPointer    UxClientData, UxCallbackArg;
  875. {
  876.     _UxCcolorview           *UxSaveCtx, *UxContext;
  877.  
  878.     UxSaveCtx = UxColorviewContext;
  879.     UxColorviewContext = UxContext =
  880.             (_UxCcolorview *) UxGetContext( UxWidget );
  881.     {
  882.     XtVaSetValues( filter_btn, XmNshowAsDefault, 0, NULL );
  883.     }
  884.     UxColorviewContext = UxSaveCtx;
  885. }
  886.  
  887. static void    focusCB_filter_text( UxWidget, UxClientData, UxCallbackArg )
  888.     Widget        UxWidget;
  889.     XtPointer    UxClientData, UxCallbackArg;
  890. {
  891.     _UxCcolorview           *UxSaveCtx, *UxContext;
  892.  
  893.     UxSaveCtx = UxColorviewContext;
  894.     UxColorviewContext = UxContext =
  895.             (_UxCcolorview *) UxGetContext( UxWidget );
  896.     {
  897.     XtVaSetValues( filter_btn, XmNshowAsDefault, 1, NULL );
  898.     }
  899.     UxColorviewContext = UxSaveCtx;
  900. }
  901.  
  902. static void    activateCB_filter_text( UxWidget, UxClientData, UxCallbackArg )
  903.     Widget        UxWidget;
  904.     XtPointer    UxClientData, UxCallbackArg;
  905. {
  906.     _UxCcolorview           *UxSaveCtx, *UxContext;
  907.  
  908.     UxSaveCtx = UxColorviewContext;
  909.     UxColorviewContext = UxContext =
  910.             (_UxCcolorview *) UxGetContext( UxWidget );
  911.     {
  912.     XtCallCallbacks (filter_btn, XmNactivateCallback, NULL);
  913.     }
  914.     UxColorviewContext = UxSaveCtx;
  915. }
  916.  
  917. static void    activateCB_filter_btn( UxWidget, UxClientData, UxCallbackArg )
  918.     Widget        UxWidget;
  919.     XtPointer    UxClientData, UxCallbackArg;
  920. {
  921.     _UxCcolorview           *UxSaveCtx, *UxContext;
  922.  
  923.     UxSaveCtx = UxColorviewContext;
  924.     UxColorviewContext = UxContext =
  925.             (_UxCcolorview *) UxGetContext( UxWidget );
  926.     {
  927.     filter_color_names();
  928.     }
  929.     UxColorviewContext = UxSaveCtx;
  930. }
  931.  
  932. static void    activateCB_ok_btn( UxWidget, UxClientData, UxCallbackArg )
  933.     Widget        UxWidget;
  934.     XtPointer    UxClientData, UxCallbackArg;
  935. {
  936.     _UxCcolorview           *UxSaveCtx, *UxContext;
  937.  
  938.     UxSaveCtx = UxColorviewContext;
  939.     UxColorviewContext = UxContext =
  940.             (_UxCcolorview *) UxGetContext( UxWidget );
  941.     {
  942.     XColor color;
  943.     double rval, gval, bval;
  944.     int i;
  945.  
  946.     color = palette_colors[active_color];
  947. /*    printf("R = %d  G = %d  B = %d\n",color.red,color.green,color.blue); */
  948.     rval = (double) color.red * 255 / 65535;
  949.     gval = (double) color.green * 255 / 65535;
  950.     bval = (double) color.blue * 255 / 65535;
  951.     AGColor[0] = (float) rval / 255.0;
  952.     AGColor[1] = (float) gval / 255.0;
  953.     AGColor[2] = (float) bval / 255.0;
  954. /*    printf("R = %f  G = %f  B = %f\n",AGColor[0],AGColor[1],AGColor[2]); */
  955.     for (i=0; i<N_PALETTE; i++)
  956.         X_to_GL_color (&palette_colors[i], current_AGColors[i]);
  957.     popdown_colorview();
  958.     }
  959.  
  960.     UxColorviewContext = UxSaveCtx;
  961. }
  962.  
  963. static void    activateCB_cancel_btn( UxWidget, UxClientData, UxCallbackArg )
  964.     Widget        UxWidget;
  965.     XtPointer    UxClientData, UxCallbackArg;
  966. {
  967.     _UxCcolorview           *UxSaveCtx, *UxContext;
  968.  
  969.     UxSaveCtx = UxColorviewContext;
  970.     UxColorviewContext = UxContext =
  971.             (_UxCcolorview *) UxGetContext( UxWidget );
  972.     {
  973.     int i;
  974.     for (i=0; i<N_PALETTE; i++)
  975.         X_to_GL_color (&palette_colors[i], current_AGColors[i]);
  976.     popdown_colorview();
  977.     }
  978.  
  979.     UxColorviewContext = UxSaveCtx;
  980. }
  981.  
  982. static void    singleSelectionCB_browser_sl( UxWidget, UxClientData, UxCallbackArg )
  983.     Widget        UxWidget;
  984.     XtPointer    UxClientData, UxCallbackArg;
  985. {
  986.     _UxCcolorview           *UxSaveCtx, *UxContext;
  987.  
  988.     UxSaveCtx = UxColorviewContext;
  989.     UxColorviewContext = UxContext =
  990.             (_UxCcolorview *) UxGetContext( UxWidget );
  991.     {
  992.     char *newname;
  993.     XmListCallbackStruct *cbs;
  994.     cbs = (XmListCallbackStruct *)UxCallbackArg;
  995.     XmStringGetLtoR (cbs->item, XmSTRING_DEFAULT_CHARSET, &newname);
  996.     if (!XParseColor (UxDisplay, sys_cmap, newname, &palette_colors[active_color])) {
  997. /*
  998.         printf ("problem parsing color %s\n", newname);
  999. */
  1000.         sprintf(msgstring, "problem parsing color %s\n", newname);
  1001.         DialogType = 1;
  1002.         popup_Message();
  1003.         return;
  1004.     }
  1005.     XStoreColor (UxDisplay,sys_cmap,&palette_colors[active_color]);
  1006.     XtVaSetValues( color_txt, XmNvalue, newname, NULL );
  1007.     XtVaSetValues( color_txt, XmNcursorPosition, strlen(newname), NULL );
  1008.     XtVaSetValues( palette[active_color],
  1009.         XmNbackground, palette_colors[active_color].pixel, NULL );
  1010.     XtVaSetValues( palette[active_color],
  1011.         XmNshadowType, XmSHADOW_IN, NULL );
  1012.     XtVaSetValues( swatch_dsp,
  1013.         XmNbackground, palette_colors[active_color].pixel, NULL );
  1014.     }
  1015.     UxColorviewContext = UxSaveCtx;
  1016. }
  1017.  
  1018.  
  1019. /*******************************************************************************
  1020.     The 'build_' function creates all the widgets
  1021.     using the resource values specified in the Property Editor.
  1022. *******************************************************************************/
  1023.  
  1024. static Widget    _Uxbuild_colorview()
  1025. {
  1026.     Widget    main_pd_p2_shell;
  1027.    Arg wargs[10];
  1028.    int n;
  1029.  
  1030.    n = 0;
  1031.    XtSetArg(wargs[n], XmNheight, 439); n++;
  1032. printf("XmNheight, 439 \n");
  1033.    XtSetArg(wargs[n], XmNwidth, 316); n++;
  1034. printf("XmNwidth, 316) \n");
  1035.    XtSetArg(wargs[n], XmNminHeight, 300); n++;
  1036.    XtSetArg(wargs[n], XmNminWidth, 200); n++;
  1037.    XtSetArg(wargs[n], XmNtitle, "Color Viewer"); n++;
  1038.    XtSetArg(wargs[n], XmNx, 300); n++;
  1039.    XtSetArg(wargs[n], XmNy, 200); n++;
  1040.  
  1041.     colorview = XtCreatePopupShell( "colorview",
  1042.             topLevelShellWidgetClass, CreateGroup,
  1043.             wargs, n);
  1044. printf(" after XtCreatePopupShell  \n");
  1045.  
  1046.     UxPutContext( colorview, (char *) UxColorviewContext );
  1047. printf(" after UxPutContext \n");
  1048.  
  1049.     body_fm = XtVaCreateManagedWidget( "body_fm",
  1050.             xmFormWidgetClass, colorview,
  1051.             XmNheight, 570,
  1052.             XmNwidth, 320,
  1053.             XmNy, 0,
  1054.             XmNx, 20,
  1055.             NULL );
  1056.  
  1057.     UxPutContext( body_fm, (char *) UxColorviewContext );
  1058.  
  1059.     main_pd = XtVaCreateManagedWidget( "main_pd",
  1060.             xmRowColumnWidgetClass, body_fm,
  1061.             XmNtopOffset, 0,
  1062.             XmNtopAttachment, XmATTACH_FORM,
  1063.             XmNrightOffset, 0,
  1064.             XmNrightAttachment, XmATTACH_FORM,
  1065.             XmNleftOffset, 0,
  1066.             XmNleftAttachment, XmATTACH_FORM,
  1067.             XmNbottomAttachment, XmATTACH_NONE,
  1068.             XmNrowColumnType, XmMENU_BAR,
  1069.             XmNborderWidth, 0,
  1070.             XmNheight, 28,
  1071.             XmNy, 30,
  1072.             XmNx, 140,
  1073.             NULL );
  1074.  
  1075.     UxPutContext( main_pd, (char *) UxColorviewContext );
  1076.  
  1077.     main_pd_p2_shell = XtVaCreatePopupShell ("main_pd_p2_shell",
  1078.             xmMenuShellWidgetClass, main_pd,
  1079.             XmNwidth, 1,
  1080.             XmNheight, 1,
  1081.             XmNallowShellResize, TRUE,
  1082.             XmNoverrideRedirect, TRUE,
  1083.             NULL );
  1084.  
  1085.     main_pd_p2 = XtVaCreateWidget( "main_pd_p2",
  1086.             xmRowColumnWidgetClass, main_pd_p2_shell,
  1087.             XmNrowColumnType, XmMENU_PULLDOWN,
  1088.             NULL );
  1089.  
  1090.     UxPutContext( main_pd_p2, (char *) UxColorviewContext );
  1091.  
  1092.     main_pd_p2_b1 = XtVaCreateManagedWidget( "main_pd_p2_b1",
  1093.             xmPushButtonGadgetClass, main_pd_p2,
  1094.             RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
  1095.             RES_CONVERT( XmNlabelString, "Edit Color ..." ),
  1096. /*
  1097.             RES_CONVERT( XmNbackground, "#BBBBBB" ),
  1098. */
  1099.             NULL );
  1100.  
  1101.     UxPutContext( main_pd_p2_b1, (char *) UxColorviewContext );
  1102.  
  1103. /*
  1104.     main_pd_p2_b2 = XtVaCreateManagedWidget( "main_pd_p2_b2",
  1105.             xmPushButtonGadgetClass, main_pd_p2,
  1106.             RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
  1107.             RES_CONVERT( XmNlabelString, "Reset" ),
  1108.             RES_CONVERT( XmNbackground, "#BBBBBB" ),
  1109.             NULL );
  1110.  
  1111.     UxPutContext( main_pd_p2_b2, (char *) UxColorviewContext );
  1112.  
  1113.     main_pd_p2_b3 = XtVaCreateManagedWidget( "main_pd_p2_b3",
  1114.             xmPushButtonGadgetClass, main_pd_p2,
  1115.             RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
  1116.             RES_CONVERT( XmNlabelString, "Demobook Colors" ),
  1117.             RES_CONVERT( XmNbackground, "#BBBBBB" ),
  1118.             NULL );
  1119.  
  1120.     UxPutContext( main_pd_p2_b3, (char *) UxColorviewContext );
  1121. */
  1122.  
  1123.     main_pd_top_b2 = XtVaCreateManagedWidget( "main_pd_top_b2",
  1124.             xmCascadeButtonWidgetClass, main_pd,
  1125.             XmNsubMenuId, main_pd_p2,
  1126.             RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
  1127.             RES_CONVERT( XmNlabelString, "Edit" ),
  1128. /*
  1129.             RES_CONVERT( XmNbackground, "#BBBBBB" ),
  1130. */
  1131.             NULL );
  1132.  
  1133.     UxPutContext( main_pd_top_b2, (char *) UxColorviewContext );
  1134.  
  1135.     colors_box = XtVaCreateManagedWidget( "colors_box",
  1136.             xmFrameWidgetClass, body_fm,
  1137.             XmNtopWidget, main_pd,
  1138.             XmNtopOffset, 0,
  1139.             XmNtopAttachment, XmATTACH_WIDGET,
  1140.             XmNrightOffset, 0,
  1141.             XmNrightAttachment, XmATTACH_FORM,
  1142.             XmNleftOffset, 0,
  1143.             XmNleftAttachment, XmATTACH_FORM,
  1144.             XmNshadowType, XmSHADOW_OUT,
  1145.             XmNmarginWidth, 8,
  1146.             XmNmarginHeight, 8,
  1147. /*
  1148.             RES_CONVERT( XmNbackground, "#BBBBBB" ),
  1149. */
  1150.             XmNshadowThickness, 5,
  1151.             XmNwidth, 320,
  1152.             XmNy, 34,
  1153.             XmNx, 0,
  1154.             NULL );
  1155.  
  1156.     UxPutContext( colors_box, (char *) UxColorviewContext );
  1157.  
  1158.     colors_fm = XtVaCreateManagedWidget( "colors_fm",
  1159.             xmFormWidgetClass, colors_box,
  1160.             RES_CONVERT( XmNtextFontList, "-Adobe-Courier-Bold-R-Normal--14-100-100-100-M-90-ISO8859-1" ),
  1161.             RES_CONVERT( XmNlabelFontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
  1162.             RES_CONVERT( XmNbuttonFontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
  1163.             XmNy, 0,
  1164.             XmNx, 0,
  1165.             XmNheight, 91,
  1166.             XmNwidth, 300,
  1167.             XmNautoUnmanage, FALSE,
  1168.             XmNallowOverlap, FALSE,
  1169.             XmNborderWidth, 0,
  1170. /*
  1171.             RES_CONVERT( XmNbackground, "#BBBBBB" ),
  1172. */
  1173.             NULL );
  1174.  
  1175.     UxPutContext( colors_fm, (char *) UxColorviewContext );
  1176.  
  1177.     color_1 = XtVaCreateManagedWidget( "color_1",
  1178.             xmDrawnButtonWidgetClass, colors_fm,
  1179.             XmNtopOffset, 0,
  1180.             XmNtopAttachment, XmATTACH_FORM,
  1181.             XmNrightPosition, 16,
  1182.             XmNrightAttachment, XmATTACH_POSITION,
  1183.             XmNleftPosition, 0,
  1184.             XmNleftAttachment, XmATTACH_POSITION,
  1185.             XmNshadowType, XmSHADOW_ETCHED_IN,
  1186.             XmNshadowThickness, 3,
  1187.             XmNheight, 24,
  1188.             RES_CONVERT( XmNbackground, 
  1189.                 GL_to_X_color_string(current_AGColors[0])),
  1190.             NULL );
  1191.  
  1192.     UxPutContext( color_1, (char *) UxColorviewContext );
  1193.  
  1194.     color_3 = XtVaCreateManagedWidget( "color_3",
  1195.             xmDrawnButtonWidgetClass, colors_fm,
  1196.             XmNtopOffset, 0,
  1197.             XmNtopAttachment, XmATTACH_FORM,
  1198.             XmNrightPosition, 33,
  1199.             XmNrightAttachment, XmATTACH_POSITION,
  1200.             XmNleftPosition, 16,
  1201.             XmNleftAttachment, XmATTACH_POSITION,
  1202.             XmNshadowType, XmSHADOW_ETCHED_IN,
  1203.             XmNshadowThickness, 3,
  1204.             XmNheight, 24,
  1205.             RES_CONVERT( XmNbackground, 
  1206.                 GL_to_X_color_string(current_AGColors[2])),
  1207.             NULL );
  1208.  
  1209.     UxPutContext( color_3, (char *) UxColorviewContext );
  1210.  
  1211.     color_5 = XtVaCreateManagedWidget( "color_5",
  1212.             xmDrawnButtonWidgetClass, colors_fm,
  1213.             XmNtopOffset, 0,
  1214.             XmNtopAttachment, XmATTACH_FORM,
  1215.             XmNrightPosition, 50,
  1216.             XmNrightAttachment, XmATTACH_POSITION,
  1217.             XmNleftPosition, 33,
  1218.             XmNleftAttachment, XmATTACH_POSITION,
  1219.             XmNshadowType, XmSHADOW_ETCHED_IN,
  1220.             XmNshadowThickness, 3,
  1221.             XmNheight, 24,
  1222.             RES_CONVERT( XmNbackground, 
  1223.                 GL_to_X_color_string(current_AGColors[4])),
  1224.             NULL );
  1225.  
  1226.     UxPutContext( color_5, (char *) UxColorviewContext );
  1227.  
  1228.     color_7 = XtVaCreateManagedWidget( "color_7",
  1229.             xmDrawnButtonWidgetClass, colors_fm,
  1230.             XmNtopPosition, 0,
  1231.             XmNtopAttachment, XmATTACH_POSITION,
  1232.             XmNrightPosition, 67,
  1233.             XmNrightAttachment, XmATTACH_POSITION,
  1234.             XmNleftPosition, 50,
  1235.             XmNleftAttachment, XmATTACH_POSITION,
  1236.             XmNshadowType, XmSHADOW_ETCHED_IN,
  1237.             XmNshadowThickness, 3,
  1238.             XmNheight, 24,
  1239.             RES_CONVERT( XmNbackground, 
  1240.                 GL_to_X_color_string(current_AGColors[6])),
  1241.             NULL );
  1242.  
  1243.     UxPutContext( color_7, (char *) UxColorviewContext );
  1244.  
  1245.     color_9 = XtVaCreateManagedWidget( "color_9",
  1246.             xmDrawnButtonWidgetClass, colors_fm,
  1247.             XmNtopOffset, 0,
  1248.             XmNtopAttachment, XmATTACH_FORM,
  1249.             XmNrightPosition, 84,
  1250.             XmNrightAttachment, XmATTACH_POSITION,
  1251.             XmNleftPosition, 67,
  1252.             XmNleftAttachment, XmATTACH_POSITION,
  1253.             XmNshadowType, XmSHADOW_ETCHED_IN,
  1254.             XmNshadowThickness, 3,
  1255.             XmNheight, 24,
  1256.             RES_CONVERT( XmNbackground, 
  1257.                 GL_to_X_color_string(current_AGColors[8])),
  1258.             NULL );
  1259.  
  1260.     UxPutContext( color_9, (char *) UxColorviewContext );
  1261.  
  1262.     color_11 = XtVaCreateManagedWidget( "color_11",
  1263.             xmDrawnButtonWidgetClass, colors_fm,
  1264.             XmNtopPosition, 0,
  1265.             XmNtopAttachment, XmATTACH_POSITION,
  1266.             XmNrightPosition, 100,
  1267.             XmNrightAttachment, XmATTACH_POSITION,
  1268.             XmNleftPosition, 84,
  1269.             XmNleftAttachment, XmATTACH_POSITION,
  1270.             XmNshadowType, XmSHADOW_ETCHED_IN,
  1271.             XmNshadowThickness, 3,
  1272.             XmNheight, 24,
  1273.             RES_CONVERT( XmNbackground, 
  1274.                 GL_to_X_color_string(current_AGColors[10])),
  1275.             NULL );
  1276.  
  1277.     UxPutContext( color_11, (char *) UxColorviewContext );
  1278.  
  1279.     color_2 = XtVaCreateManagedWidget( "color_2",
  1280.             xmDrawnButtonWidgetClass, colors_fm,
  1281.             XmNtopWidget, color_1,
  1282.             XmNtopPosition, 30,
  1283.             XmNtopOffset, 0,
  1284.             XmNtopAttachment, XmATTACH_WIDGET,
  1285.             XmNrightPosition, 16,
  1286.             XmNrightAttachment, XmATTACH_POSITION,
  1287.             XmNleftPosition, 0,
  1288.             XmNleftAttachment, XmATTACH_POSITION,
  1289.             XmNshadowType, XmSHADOW_ETCHED_IN,
  1290.             XmNshadowThickness, 3,
  1291.             XmNheight, 24,
  1292.             XmNy, 30,
  1293.             XmNx, 0,
  1294.             RES_CONVERT( XmNbackground, 
  1295.                 GL_to_X_color_string(current_AGColors[1])),
  1296.             NULL );
  1297.  
  1298.     UxPutContext( color_2, (char *) UxColorviewContext );
  1299.  
  1300.     color_4 = XtVaCreateManagedWidget( "color_4",
  1301.             xmDrawnButtonWidgetClass, colors_fm,
  1302.             XmNtopWidget, color_3,
  1303.             XmNtopOffset, 0,
  1304.             XmNtopAttachment, XmATTACH_WIDGET,
  1305.             XmNrightPosition, 33,
  1306.             XmNrightAttachment, XmATTACH_POSITION,
  1307.             XmNleftPosition, 16,
  1308.             XmNleftAttachment, XmATTACH_POSITION,
  1309.             XmNshadowType, XmSHADOW_ETCHED_IN,
  1310.             XmNshadowThickness, 3,
  1311.             XmNheight, 24,
  1312.             XmNwidth, 51,
  1313.             XmNy, 30,
  1314.             XmNx, 48,
  1315.             RES_CONVERT( XmNbackground, 
  1316.                 GL_to_X_color_string(current_AGColors[3])),
  1317.             NULL );
  1318.  
  1319.     UxPutContext( color_4, (char *) UxColorviewContext );
  1320.  
  1321.     color_6 = XtVaCreateManagedWidget( "color_6",
  1322.             xmDrawnButtonWidgetClass, colors_fm,
  1323.             XmNtopWidget, color_5,
  1324.             XmNtopOffset, 0,
  1325.             XmNtopAttachment, XmATTACH_WIDGET,
  1326.             XmNrightPosition, 50,
  1327.             XmNrightAttachment, XmATTACH_POSITION,
  1328.             XmNleftPosition, 33,
  1329.             XmNleftAttachment, XmATTACH_POSITION,
  1330.             XmNshadowType, XmSHADOW_ETCHED_IN,
  1331.             XmNshadowThickness, 3,
  1332.             XmNheight, 24,
  1333.             RES_CONVERT( XmNbackground, 
  1334.                 GL_to_X_color_string(current_AGColors[5])),
  1335.             NULL );
  1336.  
  1337.     UxPutContext( color_6, (char *) UxColorviewContext );
  1338.  
  1339.     color_8 = XtVaCreateManagedWidget( "color_8",
  1340.             xmDrawnButtonWidgetClass, colors_fm,
  1341.             XmNtopWidget, color_7,
  1342.             XmNtopOffset, 0,
  1343.             XmNtopAttachment, XmATTACH_WIDGET,
  1344.             XmNrightPosition, 67,
  1345.             XmNrightAttachment, XmATTACH_POSITION,
  1346.             XmNleftPosition, 50,
  1347.             XmNleftAttachment, XmATTACH_POSITION,
  1348.             XmNshadowType, XmSHADOW_ETCHED_IN,
  1349.             XmNshadowThickness, 3,
  1350.             XmNheight, 24,
  1351.             RES_CONVERT( XmNbackground, 
  1352.                 GL_to_X_color_string(current_AGColors[7])),
  1353.             NULL );
  1354.  
  1355.     UxPutContext( color_8, (char *) UxColorviewContext );
  1356.  
  1357.     color_10 = XtVaCreateManagedWidget( "color_10",
  1358.             xmDrawnButtonWidgetClass, colors_fm,
  1359.             XmNtopWidget, color_9,
  1360.             XmNtopPosition, 0,
  1361.             XmNtopOffset, 0,
  1362.             XmNtopAttachment, XmATTACH_WIDGET,
  1363.             XmNrightPosition, 84,
  1364.             XmNrightAttachment, XmATTACH_POSITION,
  1365.             XmNleftPosition, 67,
  1366.             XmNleftAttachment, XmATTACH_POSITION,
  1367.             XmNshadowType, XmSHADOW_ETCHED_IN,
  1368.             XmNshadowThickness, 3,
  1369.             XmNheight, 24,
  1370.             RES_CONVERT( XmNbackground, 
  1371.                 GL_to_X_color_string(current_AGColors[9])),
  1372.             NULL );
  1373.  
  1374.     UxPutContext( color_10, (char *) UxColorviewContext );
  1375.  
  1376.     color_12 = XtVaCreateManagedWidget( "color_12",
  1377.             xmDrawnButtonWidgetClass, colors_fm,
  1378.             XmNtopWidget, color_11,
  1379.             XmNtopPosition, 0,
  1380.             XmNtopOffset, 0,
  1381.             XmNtopAttachment, XmATTACH_WIDGET,
  1382.             XmNrightPosition, 100,
  1383.             XmNrightAttachment, XmATTACH_POSITION,
  1384.             XmNleftPosition, 84,
  1385.             XmNleftAttachment, XmATTACH_POSITION,
  1386.             XmNshadowType, XmSHADOW_ETCHED_IN,
  1387.             XmNshadowThickness, 3,
  1388.             XmNheight, 24,
  1389.             RES_CONVERT( XmNbackground, 
  1390.                 GL_to_X_color_string(current_AGColors[11])),
  1391.             NULL );
  1392.  
  1393.     UxPutContext( color_12, (char *) UxColorviewContext );
  1394.  
  1395.     swatch_fm = XtVaCreateManagedWidget( "swatch_fm",
  1396.             xmFormWidgetClass, colors_fm,
  1397.             XmNtopWidget, color_2,
  1398.             XmNtopOffset, 5,
  1399.             XmNtopAttachment, XmATTACH_WIDGET,
  1400.             XmNrightPosition, 50,
  1401.             XmNrightOffset, 2,
  1402.             XmNrightAttachment, XmATTACH_POSITION,
  1403.             XmNleftOffset, 0,
  1404.             XmNleftAttachment, XmATTACH_FORM,
  1405.             XmNbottomOffset, 0,
  1406.             XmNbottomAttachment, XmATTACH_FORM,
  1407.             RES_CONVERT( XmNbackground, "#BBBBBB" ),
  1408.             XmNshadowType, XmSHADOW_IN,
  1409.             XmNshadowThickness, 3,
  1410.             NULL );
  1411.  
  1412.     UxPutContext( swatch_fm, (char *) UxColorviewContext );
  1413.  
  1414.     swatch_dsp = XtVaCreateManagedWidget( "swatch_dsp",
  1415.                         xmDrawingAreaWidgetClass, swatch_fm,
  1416. /*
  1417.             XmNtopWidget, color_2,
  1418.             XmNtopOffset, 5,
  1419.             XmNtopAttachment, XmATTACH_WIDGET,
  1420.             XmNrightPosition, 50,
  1421.             XmNrightAttachment, XmATTACH_POSITION,
  1422.             XmNleftPosition, 0,
  1423.             XmNleftAttachment, XmATTACH_POSITION,
  1424. */
  1425.             XmNtopOffset, 3,
  1426.             XmNtopAttachment, XmATTACH_FORM,
  1427.             XmNrightOffset, 3,
  1428.             XmNrightAttachment, XmATTACH_FORM,
  1429.             XmNleftOffset, 3,
  1430.             XmNleftAttachment, XmATTACH_FORM,
  1431.             XmNbottomOffset, 3,
  1432.             XmNbottomAttachment, XmATTACH_FORM,
  1433.             XmNresizePolicy, XmRESIZE_NONE,
  1434.             XmNheight, 33,
  1435.             XmNwidth, 10,
  1436.             RES_CONVERT( XmNbackground, 
  1437.                 GL_to_X_color_string(current_AGColors[0]) ),
  1438.             NULL );
  1439.  
  1440.     UxPutContext( swatch_dsp, (char *) UxColorviewContext );
  1441.  
  1442.     color_txt = XtVaCreateManagedWidget( "color_txt",
  1443.             xmTextFieldWidgetClass, colors_fm,
  1444. /*
  1445.             RES_CONVERT( XmNbackground, "#7777BB" ),
  1446. */
  1447.             RES_CONVERT( XmNfontList, "-Adobe-Courier-Bold-R-Normal--14-100-100-100-M-90-ISO8859-1" ),
  1448. /*            XmNeditable, FALSE, */
  1449.             XmNleftWidget, swatch_fm,
  1450.             XmNleftOffset, 0,
  1451.             XmNleftAttachment, XmATTACH_WIDGET,
  1452.             XmNtopWidget, color_8,
  1453.             XmNtopOffset, 6,
  1454.             XmNtopAttachment, XmATTACH_WIDGET,
  1455.             XmNrightOffset, 0,
  1456.             XmNrightAttachment, XmATTACH_FORM,
  1457. /*
  1458.             XmNheight, 35,
  1459.             XmNwidth, 155,
  1460.             XmNy, 50,
  1461.             XmNx, 150,
  1462. */
  1463.             NULL );
  1464.  
  1465.     UxPutContext( color_txt, (char *) UxColorviewContext );
  1466.  
  1467.     browser_box = XtVaCreateManagedWidget( "browser_box",
  1468.             xmFrameWidgetClass, body_fm,
  1469.             XmNtopWidget, colors_box,
  1470.             XmNtopOffset, 0,
  1471.             XmNtopAttachment, XmATTACH_WIDGET,
  1472.             XmNrightOffset, 0,
  1473.             XmNrightAttachment, XmATTACH_FORM,
  1474.             XmNleftOffset, 0,
  1475.             XmNleftAttachment, XmATTACH_FORM,
  1476.             XmNbottomOffset, 0,
  1477.             XmNbottomAttachment, XmATTACH_FORM,
  1478.             XmNshadowType, XmSHADOW_OUT,
  1479. /*
  1480.             RES_CONVERT( XmNbackground, "#BBBBBB" ),
  1481.             XmNshadowThickness, 5,
  1482. */
  1483.             XmNheight, 360,
  1484.             XmNwidth, 316,
  1485.             XmNy, 80,
  1486.             XmNx, 0,
  1487.             NULL );
  1488.  
  1489.     UxPutContext( browser_box, (char *) UxColorviewContext );
  1490.  
  1491.     browser_fm = XtVaCreateManagedWidget( "browser_fm",
  1492.             xmFormWidgetClass, browser_box,
  1493.             XmNverticalSpacing, 5,
  1494.             XmNhorizontalSpacing, 5,
  1495.             XmNborderWidth, 0,
  1496. /*
  1497.             RES_CONVERT( XmNbackground, "#BBBBBB" ),
  1498. */
  1499.             XmNheight, 360,
  1500.             XmNwidth, 310,
  1501.             XmNy, 0,
  1502.             XmNx, 0,
  1503.             NULL );
  1504.  
  1505.     UxPutContext( browser_fm, (char *) UxColorviewContext );
  1506.  
  1507.     filter_lbl = XtVaCreateManagedWidget( "filter_lbl",
  1508.             xmLabelGadgetClass, browser_fm,
  1509.             XmNtopAttachment, XmATTACH_FORM,
  1510.             XmNleftAttachment, XmATTACH_FORM,
  1511.             RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
  1512.             RES_CONVERT( XmNlabelString, "Name Filter:" ),
  1513.             XmNalignment, XmALIGNMENT_BEGINNING,
  1514. /*
  1515.             RES_CONVERT( XmNbackground, "#BBBBBB" ),
  1516. */
  1517.             NULL );
  1518.  
  1519.     UxPutContext( filter_lbl, (char *) UxColorviewContext );
  1520.  
  1521.     filter_text = XtVaCreateManagedWidget( "filter_text",
  1522.             xmTextWidgetClass, browser_fm,
  1523. /*
  1524.             RES_CONVERT( XmNbackground, "#7777BB" ),
  1525. */
  1526.             RES_CONVERT( XmNtextFontList, "-Adobe-Courier-Bold-R-Normal--14-100-100-100-M-90-ISO8859-1" ),
  1527.             XmNtopWidget, filter_lbl,
  1528.             XmNtopAttachment, XmATTACH_WIDGET,
  1529.             XmNrightAttachment, XmATTACH_FORM,
  1530.             XmNleftAttachment, XmATTACH_FORM,
  1531.             XmNvalue, "[A-Z]*",
  1532.             NULL );
  1533.  
  1534.     UxPutContext( filter_text, (char *) UxColorviewContext );
  1535.  
  1536.     browser_lbl = XtVaCreateManagedWidget( "browser_lbl",
  1537.             xmLabelGadgetClass, browser_fm,
  1538.             XmNtopWidget, filter_text,
  1539.             XmNtopAttachment, XmATTACH_WIDGET,
  1540.             XmNleftAttachment, XmATTACH_FORM,
  1541.             RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
  1542.             RES_CONVERT( XmNlabelString, "Color Database:" ),
  1543. /*
  1544.             RES_CONVERT( XmNbackground, "#BBBBBB" ),
  1545. */
  1546.             NULL );
  1547.  
  1548.     UxPutContext( browser_lbl, (char *) UxColorviewContext );
  1549.  
  1550.     ok_btn = XtVaCreateManagedWidget( "ok_btn",
  1551.             xmPushButtonWidgetClass, browser_fm,
  1552.             XmNmarginRight, 7,
  1553.             XmNmarginLeft, 7,
  1554.             XmNrightPosition, 30,
  1555.             XmNrightAttachment, XmATTACH_POSITION,
  1556.             XmNleftPosition, 5,
  1557.             XmNleftAttachment, XmATTACH_POSITION,
  1558.             XmNbottomOffset, 2,
  1559.             XmNbottomAttachment, XmATTACH_FORM,
  1560.             XmNrecomputeSize, FALSE,
  1561.             RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
  1562.             RES_CONVERT( XmNlabelString, "Done" ),
  1563. /*
  1564.             RES_CONVERT( XmNbackground, "#BBBBBB" ),
  1565. */
  1566.             XmNheight, 26,
  1567.             XmNwidth, 92,
  1568.             NULL );
  1569.  
  1570.     UxPutContext( ok_btn, (char *) UxColorviewContext );
  1571.  
  1572.     filter_btn = XtVaCreateManagedWidget( "filter_btn",
  1573.             xmPushButtonWidgetClass, browser_fm,
  1574.             XmNmarginRight, 7,
  1575.             XmNmarginLeft, 7,
  1576.             XmNrightPosition, 62,
  1577.             XmNrightAttachment, XmATTACH_POSITION,
  1578.             XmNleftPosition, 37,
  1579.             XmNleftAttachment, XmATTACH_POSITION,
  1580.             XmNbottomOffset, 2,
  1581.             XmNbottomAttachment, XmATTACH_FORM,
  1582.             XmNrecomputeSize, FALSE,
  1583.             RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
  1584.             RES_CONVERT( XmNlabelString, "Filter" ),
  1585. /*
  1586.             RES_CONVERT( XmNbackground, "#BBBBBB" ),
  1587. */
  1588.             RES_CONVERT( XmNaccelerators, view_trans ),
  1589.             XmNheight, 26,
  1590.             XmNwidth, 74,
  1591.             NULL );
  1592.  
  1593.     UxPutContext( filter_btn, (char *) UxColorviewContext );
  1594.  
  1595.     cancel_btn = XtVaCreateManagedWidget( "cancel_btn",
  1596.             xmPushButtonWidgetClass, browser_fm,
  1597.             XmNmarginRight, 7,
  1598.             XmNmarginLeft, 7,
  1599.             XmNrightPosition, 95,
  1600.             XmNrightAttachment, XmATTACH_POSITION,
  1601.             XmNleftPosition, 70,
  1602.             XmNleftAttachment, XmATTACH_POSITION,
  1603.             XmNbottomOffset, 2,
  1604.             XmNbottomAttachment, XmATTACH_FORM,
  1605.             XmNrecomputeSize, FALSE,
  1606.             RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
  1607.             RES_CONVERT( XmNlabelString, "Cancel" ),
  1608. /*
  1609.             RES_CONVERT( XmNbackground, "#BBBBBB" ),
  1610. */
  1611.             XmNheight, 26,
  1612.             XmNwidth, 74,
  1613.             NULL );
  1614.  
  1615.     UxPutContext( cancel_btn, (char *) UxColorviewContext );
  1616.  
  1617.     browser_sw = XtVaCreateManagedWidget( "browser_sw",
  1618.             xmScrolledWindowWidgetClass, browser_fm,
  1619.             RES_CONVERT( XmNbackground, "#7777BB" ),
  1620.             XmNtopWidget, browser_lbl,
  1621.             XmNtopAttachment, XmATTACH_WIDGET,
  1622.             XmNrightAttachment, XmATTACH_FORM,
  1623.             XmNleftAttachment, XmATTACH_FORM,
  1624.             XmNbottomOffset, 40,
  1625.             XmNbottomAttachment, XmATTACH_FORM,
  1626.             XmNscrollingPolicy, XmAPPLICATION_DEFINED,
  1627.             XmNscrollBarDisplayPolicy, XmSTATIC,
  1628.             XmNborderWidth, 0,
  1629.             NULL );
  1630.  
  1631.     UxPutContext( browser_sw, (char *) UxColorviewContext );
  1632.  
  1633.     browser_sl = XtVaCreateManagedWidget( "browser_sl",
  1634.             xmListWidgetClass, browser_sw,
  1635. /*
  1636.             RES_CONVERT( XmNbackground, "#7777BB" ),
  1637. */
  1638.             XmNselectionPolicy, XmSINGLE_SELECT,
  1639.             XmNlistSpacing, 2,
  1640.             XmNvisibleItemCount, 6,
  1641.             XmNlistMarginHeight, 2,
  1642.             RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
  1643.             XmNheight, 180,
  1644.             XmNwidth, 284,
  1645.             XmNy, 0,
  1646.             XmNx, 0,
  1647.             NULL );
  1648.  
  1649.     UxPutContext( browser_sl, (char *) UxColorviewContext );
  1650.  
  1651.     XtAddCallback( colorview, XmNdestroyCallback,
  1652.             UxFreeClientDataCB,
  1653.             (XtPointer) UxColorviewContext );
  1654.  
  1655.     XtAddCallback( colorview, XmNdestroyCallback,
  1656.             destroyCB_colorview,
  1657.             (XtPointer) UxColorviewContext );
  1658.  
  1659.     XtAddCallback( main_pd_p2_b1, XmNactivateCallback,
  1660.             activateCB_main_pd_p2_b1,
  1661.             (XtPointer) UxColorviewContext );
  1662.  
  1663. /*
  1664.     XtAddCallback( main_pd_p2_b2, XmNactivateCallback,
  1665.             activateCB_main_pd_p2_b2,
  1666.             (XtPointer) UxColorviewContext );
  1667.  
  1668.     XtAddCallback( main_pd_p2_b3, XmNactivateCallback,
  1669.             activateCB_main_pd_p2_b3,
  1670.             (XtPointer) UxColorviewContext );
  1671. */
  1672.  
  1673.     XtAddCallback( color_1, XmNactivateCallback,
  1674.             activateCB_color_1,
  1675.             (XtPointer) UxColorviewContext );
  1676.  
  1677.     XtAddCallback( color_5, XmNactivateCallback,
  1678.             activateCB_color_5,
  1679.             (XtPointer) UxColorviewContext );
  1680.  
  1681.     XtAddCallback( color_7, XmNactivateCallback,
  1682.             activateCB_color_7,
  1683.             (XtPointer) UxColorviewContext );
  1684.  
  1685.     XtAddCallback( color_9, XmNactivateCallback,
  1686.             activateCB_color_9,
  1687.             (XtPointer) UxColorviewContext );
  1688.  
  1689.     XtAddCallback( color_11, XmNactivateCallback,
  1690.             activateCB_color_11,
  1691.             (XtPointer) UxColorviewContext );
  1692.  
  1693.     XtAddCallback( color_2, XmNactivateCallback,
  1694.             activateCB_color_2,
  1695.             (XtPointer) UxColorviewContext );
  1696.  
  1697.     XtAddCallback( color_6, XmNactivateCallback,
  1698.             activateCB_color_6,
  1699.             (XtPointer) UxColorviewContext );
  1700.  
  1701.     XtAddCallback( color_8, XmNactivateCallback,
  1702.             activateCB_color_8,
  1703.             (XtPointer) UxColorviewContext );
  1704.  
  1705.     XtAddCallback( color_10, XmNactivateCallback,
  1706.             activateCB_color_10,
  1707.             (XtPointer) UxColorviewContext );
  1708.  
  1709.     XtAddCallback( color_12, XmNactivateCallback,
  1710.             activateCB_color_12,
  1711.             (XtPointer) UxColorviewContext );
  1712.  
  1713.     XtAddCallback( color_3, XmNactivateCallback,
  1714.             activateCB_color_3,
  1715.             (XtPointer) UxColorviewContext );
  1716.  
  1717.     XtAddCallback( color_4, XmNactivateCallback,
  1718.             activateCB_color_4,
  1719.             (XtPointer) UxColorviewContext );
  1720.  
  1721.     XtAddCallback( color_txt, XmNactivateCallback,
  1722.             activateCB_color_txt,
  1723.             (XtPointer) UxColorviewContext );
  1724.  
  1725.     XtVaSetValues( browser_fm, XmNdefaultButton, ok_btn, NULL );
  1726.  
  1727.     XtAddCallback( filter_text, XmNlosingFocusCallback,
  1728.             losingFocusCB_filter_text,
  1729.             (XtPointer) UxColorviewContext );
  1730.     XtAddCallback( filter_text, XmNfocusCallback,
  1731.             focusCB_filter_text,
  1732.             (XtPointer) UxColorviewContext );
  1733.     XtAddCallback( filter_text, XmNactivateCallback,
  1734.             activateCB_filter_text,
  1735.             (XtPointer) UxColorviewContext );
  1736.  
  1737.     XtAddCallback( filter_btn, XmNactivateCallback,
  1738.             activateCB_filter_btn,
  1739.             (XtPointer) UxColorviewContext );
  1740.  
  1741.     XtAddCallback( browser_sl, XmNsingleSelectionCallback,
  1742.             singleSelectionCB_browser_sl,
  1743.             (XtPointer) UxColorviewContext );
  1744.  
  1745.     XtAddCallback( ok_btn, XmNactivateCallback,
  1746.             activateCB_ok_btn,
  1747.             (XtPointer) UxColorviewContext );
  1748.  
  1749.     XtAddCallback( cancel_btn, XmNactivateCallback,
  1750.             activateCB_cancel_btn,
  1751.             (XtPointer) UxColorviewContext );
  1752.  
  1753.  
  1754.     return ( colorview );
  1755. }
  1756.  
  1757.  
  1758. /*******************************************************************************
  1759.     The following function includes the code that was entered
  1760.     in the 'Initial Code' and 'Final Code' sections of the
  1761.     Declarations Editor.  This function is called from the
  1762.     'Interface function' below.
  1763. *******************************************************************************/
  1764.  
  1765. static Widget    _Ux_create_colorview()
  1766. {
  1767.     Widget                 rtrn;
  1768.     _UxCcolorview           *UxContext;
  1769.  
  1770.     UxColorviewContext = UxContext =
  1771.         (_UxCcolorview *) XtMalloc( sizeof(_UxCcolorview) );
  1772.  
  1773.     {
  1774.     active_color = 0;
  1775.     rtrn = _Uxbuild_colorview();
  1776.  
  1777.     setup_palette ();    /* make table of palette boxes */
  1778.     setup_colors ();     /* allocate read/write colorcells */
  1779.     create_coloredit (colorview, &palette_colors[0], &editor_color);
  1780.     {
  1781.        Atom a;
  1782.        a = XmInternAtom (UxDisplay, "WM_DELETE_WINDOW", FALSE);
  1783.        XmAddWMProtocols (colorview, &a, 1);
  1784.        XmAddWMProtocolCallback (colorview, a, WmCloseCallback, 0);
  1785.     }
  1786.     XtInstallAccelerators (filter_text, filter_btn);
  1787.     read_color_db ();
  1788. /*
  1789.     activate_color (0);
  1790.     SetWMhints( colorview );
  1791.     UxPopupInterface (colorview, no_grab);
  1792.     return (colorview);
  1793. */
  1794.     XtRealizeWidget( colorview );
  1795.  
  1796.     SetWMhints( colorview );
  1797.  
  1798.     return (rtrn);
  1799.     }
  1800. }
  1801.  
  1802. /*******************************************************************************
  1803.     The following is the 'Interface function' which is the
  1804.     external entry point for creating this interface.
  1805.     This function should be called from your application or from
  1806.     a callback function.
  1807. *******************************************************************************/
  1808.  
  1809. Widget create_colorview()
  1810. {
  1811.     Widget            _Uxrtrn;
  1812.  
  1813.     _Uxrtrn = _Ux_create_colorview();
  1814.  
  1815.     return ( _Uxrtrn );
  1816. }
  1817.  
  1818. void popup_colorview()
  1819. {
  1820.     Boolean color_found;
  1821.     char *xcolorstring;
  1822.     int i, isav;
  1823.  
  1824.     if (CVwin <= 0) {
  1825. /*
  1826.         sprintf(msgstring, "\nLoading in Color Viewer ...\n");
  1827.         UxPopupInterface(create_Working(), no_grab);
  1828.         handleMotifInterfaceEvents();
  1829. */
  1830. /*
  1831.         XtVaSetValues( color_1, RES_CONVERT( XmNbackground, 
  1832.             GL_to_X_color_string(current_AGColors[0])), NULL );
  1833.         XtVaSetValues( color_2, RES_CONVERT( XmNbackground, 
  1834.             GL_to_X_color_string(current_AGColors[1])), NULL );
  1835.         XtVaSetValues( color_3, RES_CONVERT( XmNbackground, 
  1836.             GL_to_X_color_string(current_AGColors[2])), NULL );
  1837.         XtVaSetValues( color_4, RES_CONVERT( XmNbackground, 
  1838.             GL_to_X_color_string(current_AGColors[3])), NULL );
  1839.         XtVaSetValues( color_5, RES_CONVERT( XmNbackground, 
  1840.             GL_to_X_color_string(current_AGColors[4])), NULL );
  1841.         XtVaSetValues( color_6, RES_CONVERT( XmNbackground, 
  1842.             GL_to_X_color_string(current_AGColors[5])), NULL );
  1843.         XtVaSetValues( color_7, RES_CONVERT( XmNbackground, 
  1844.             GL_to_X_color_string(current_AGColors[6])), NULL );
  1845.         XtVaSetValues( color_8, RES_CONVERT( XmNbackground, 
  1846.             GL_to_X_color_string(current_AGColors[7])), NULL );
  1847.         XtVaSetValues( color_9, RES_CONVERT( XmNbackground, 
  1848.             GL_to_X_color_string(current_AGColors[8])), NULL );
  1849.         XtVaSetValues( color_10, RES_CONVERT( XmNbackground, 
  1850.             GL_to_X_color_string(current_AGColors[9])), NULL );
  1851.         XtVaSetValues( color_11, RES_CONVERT( XmNbackground, 
  1852.             GL_to_X_color_string(current_AGColors[10])), NULL );
  1853.         XtVaSetValues( color_12, RES_CONVERT( XmNbackground, 
  1854.             GL_to_X_color_string(current_AGColors[11])), NULL );
  1855.         setup_palette();
  1856. */
  1857.  
  1858.         color_found = FALSE;
  1859.         for (i=0; i<N_PALETTE; i++) {
  1860. /*
  1861.         XStoreColor (UxDisplay, sys_cmap, &palette_colors[i]);
  1862. */
  1863.         if ((AGColor[0] == current_AGColors[i][0]) &&
  1864.             (AGColor[1] == current_AGColors[i][1]) &&
  1865.             (AGColor[2] == current_AGColors[i][2])) {
  1866.             color_found = TRUE;
  1867.             isav = i;
  1868.         }
  1869.         }
  1870.         if (color_found) {
  1871.         activate_color (isav);
  1872.         }
  1873.         else {
  1874.         xcolorstring = GL_to_X_color_string (AGColor);
  1875. /*        printf ("Color %s not found in palette.\n", xcolorstring); */
  1876.         if (!XParseColor (UxDisplay, sys_cmap, 
  1877.                           xcolorstring, &palette_colors[11])) {
  1878.             sprintf(msgstring, "problem parsing color %s\n", xcolorstring);
  1879.             DialogType = 1;
  1880.             popup_Message();
  1881.             activate_color (0);
  1882.             goto POPUP;
  1883.         }
  1884.         XStoreColor (UxDisplay, sys_cmap, &palette_colors[11]);
  1885.         activate_color (11);
  1886.         }
  1887. POPUP:        UxPopupInterface (colorview, no_grab);
  1888.         CVwin = 99;
  1889.  
  1890. /*
  1891.         UxPopdownInterface(Working);
  1892.         handleMotifInterfaceEvents();
  1893. */
  1894.     }
  1895.  
  1896. }
  1897.  
  1898. void popdown_colorview()
  1899. {
  1900.     XmListDeselectAllItems (browser_sl);
  1901.     XmListSetPos (browser_sl, 1);
  1902.     UxPopdownInterface (colorview);
  1903.     CVwin = -1;
  1904. }
  1905.  
  1906. char* GL_to_X_color_string (color)
  1907.     float color[3];
  1908. {
  1909.     int rhex,ghex,bhex;
  1910.     static char color_string_buf[32];
  1911.  
  1912.     rhex = (int) (color[0] * 255);
  1913.     ghex = (int) (color[1] * 255);
  1914.     bhex = (int) (color[2] * 255);
  1915.     sprintf (color_string_buf, "#%02x%02x%02x", rhex, ghex, bhex);
  1916. /*    printf (" %s\n", color_string_buf); */
  1917.     return color_string_buf;
  1918. }
  1919.  
  1920. static void X_to_GL_color (color, glcolor)
  1921.     XColor* color;
  1922.     float   glcolor[3];
  1923. {
  1924.     double rval,gval,bval;
  1925.  
  1926.     rval = (double) color->red * 255 / 65535;
  1927.     gval = (double) color->green * 255 / 65535;
  1928.     bval = (double) color->blue * 255 / 65535;
  1929.     glcolor[0] = (float) rval / 255.0;
  1930.     glcolor[1] = (float) gval / 255.0;
  1931.     glcolor[2] = (float) bval / 255.0;
  1932.  
  1933. /*    printf("R = %f  G = %f  B = %f\n", glcolor[0], glcolor[1], glcolor[2]); */
  1934. }
  1935.  
  1936. Boolean GLParseColor (input_string, color_string_buf)
  1937.     char *input_string;
  1938.     char *color_string_buf;
  1939. {
  1940.     char *newname;
  1941.     int rhex, ghex, bhex;
  1942.     double r, g, b;
  1943.     char s[2];
  1944.     char **ptr;
  1945.     char *red_string, *grn_string, *blu_string;
  1946.     int len;
  1947.     int i;
  1948.  
  1949.     newname = (char *)malloc( sizeof(char) * (strlen(input_string)+1));
  1950.     red_string = (char *)malloc(sizeof(char) * 32);
  1951.     grn_string = (char *)malloc(sizeof(char) * 32);
  1952.     blu_string = (char *)malloc(sizeof(char) * 32);
  1953.     ptr = (char **)malloc(sizeof(char) * 100);
  1954.  
  1955.     newname[0] = '\0';
  1956.     strcpy(newname, input_string);
  1957.     red_string[0] = '\0';
  1958.     grn_string[0] = '\0';
  1959.     blu_string[0] = '\0';
  1960.     strcpy(s," ");
  1961.     red_string = strtok(newname, s);
  1962.     grn_string = strtok(NULL, s);
  1963.     blu_string = strtok(NULL, s);
  1964.     if((red_string == NULL) || (grn_string == NULL) || (blu_string == NULL))
  1965.         goto ERROR;
  1966.     len = strlen(red_string);
  1967.     for(i=0; i<len; i++)
  1968.         if((isdigit(red_string[i]) == 0) && (red_string[i] != '.'))
  1969.         goto ERROR;
  1970.     len = strlen(grn_string);
  1971.     for(i=0; i<len; i++)
  1972.         if((isdigit(grn_string[i]) == 0) && (grn_string[i] != '.'))
  1973.         goto ERROR;
  1974.     len = strlen(blu_string);
  1975.     for(i=0; i<len; i++)
  1976.         if((isdigit(blu_string[i]) == 0) && (blu_string[i] != '.'))
  1977.         goto ERROR;
  1978.     r = strtod (red_string, ptr);
  1979.     g = strtod (grn_string, ptr);
  1980.     b = strtod (blu_string, ptr);
  1981. /*    printf ("r g b = %.2f %.2f %.2f   ", r, g, b); */
  1982.  
  1983.     rhex = (int) (r * 255);
  1984.     ghex = (int) (g * 255);
  1985.     bhex = (int) (b * 255);
  1986. /*    printf ("rhex ghex bhex = %03d %03d %03d\n", rhex, ghex, bhex); */
  1987.     if( ((rhex>=0) && (rhex<=255)) && 
  1988.         ((ghex>=0) && (ghex<=255)) && 
  1989.         ((bhex>=0) && (bhex<=255)) ) {
  1990.         sprintf (color_string_buf, "#%02x%02x%02x", rhex, ghex, bhex);
  1991. /*        printf (" %s\n", color_string_buf); */
  1992. /*
  1993.         free(newname);
  1994.         free(ptr);
  1995.         free(red_string);
  1996.         free(grn_string);
  1997.         free(blu_string);
  1998. */
  1999.         return(TRUE);
  2000.     }
  2001.     else {
  2002. /*
  2003. ERROR:        free(newname);
  2004.         free(ptr);
  2005.         free(red_string);
  2006.         free(grn_string);
  2007.         free(blu_string);
  2008. */
  2009. ERROR:      return(FALSE);
  2010.     }
  2011. }
  2012.  
  2013. /*******************************************************************************
  2014.     END OF FILE
  2015. *******************************************************************************/
  2016.  
  2017.